package components {
	import mx.containers.Canvas;
	import mx.events.FlexEvent;
	
	import common.Common;
	
	import components.Room;

	public class RoomBar extends Canvas {
		
		//------------------------------------------------------------
        //
        // class constants
        //
        //------------------------------------------------------------
		
		public static const HORIZONTAL:String = "horizontal";
		public static const VERTICAL:String = "vertical";
		
		private static var _roomTmpID:int;
		private static var _roomID:int;
		
		//------------------------------------------------------------
        //
        // object vaiables
        //
        //------------------------------------------------------------
		
		//------------------------------
        // alignType
        //------------------------------

        /**
         * align type of rooms, has two types: horizontal or vertical
         */
        private var _alignType:String;

        public function get alignType():String {
            return _alignType;
        }

        public function set alignType(alignType:String):void {
            _alignType = alignType;
        }
        
        //------------------------------
        // roomCount
        //------------------------------

        /**
         * how many room should be added to this bar
         */
        private var _roomCount:int;

        public function get roomCount():int {
            return _roomCount;
        }

        public function set roomCount(roomCount:int):void {
            _roomCount = roomCount;
        }
        
		//------------------------------------------------------------
        //
        // constructor
        //
        //------------------------------------------------------------
		
		public function RoomBar() {
			super();
			
			addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete);
		}
		
		//------------------------------------------------------------
        //
        // event handlers
        //
        //------------------------------------------------------------
        
        private function onCreationComplete(e:FlexEvent):void {
        	for (var i:int = 0; i < roomCount; ++i) {
        		var room:Room = new Room();
        		
        		if (alignType == HORIZONTAL) {
        			room.x = Room.STANDARD_WIDTH * i + Common.ROOM_ROOM_GAP * i;
        		}
        		
        		if (alignType == VERTICAL) {
        			room.y = Room.STANDARD_HEIGHT * i + Common.ROOM_ROOM_GAP * i;
        		}
        		
        		addChild(room);
        		
        		++_roomTmpID;
        		
        		if (_roomTmpID == 13 || _roomTmpID == 46 || _roomTmpID == 65 || _roomTmpID == 138) {
        			room.content = "球架";
        			room.status = Room.INVALID;
        		} else {
        			++_roomID;
        			room.roomID = _roomID;
        			room.roomNo = "R" + _roomID.toString();
	                room.content = room.roomNo;
	                room.status = Room.UNBOOKED;
	                
	                parentApplication.rooms[_roomID] = room;
        		}
        	}
        }
		
	}
}